package cn.t.web.android;

import cn.t.annotation.Runtime;
import cn.t.core.mode.Result;
import cn.t.dto.device.DeviceVersionDTO;
import cn.t.facade.device.DeviceFacade;
import cn.t.runtime.dto.NoArgRequest;
import cn.t.vo.andriod.AndroidDeviceAngleVO;
import cn.t.vo.andriod.AndroidDeviceVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 安卓设备服务
 *
 * @author s
 * @since 2024-07-04
 */
@Slf4j
@RestController
@RequestMapping("runtime/device")
// "安卓设备服务")
@AllArgsConstructor
@Runtime
public class AndroidDeviceController {

    private final DeviceFacade deviceFacade;

    /**
     * 更新设备版本号
     */
    @PostMapping("/updateVersion")
    public Boolean updateVersion(@RequestBody DeviceVersionDTO req) {
        return this.deviceFacade.updateVersion(req);
    }

    /**
     * 根据imei查询设备信息
     */
    @PostMapping("/queryByImei")
    public AndroidDeviceVO queryByImei(@RequestBody NoArgRequest req) {
        return this.deviceFacade.getDeviceByImei(req.getImei());
    }

    /**
     * 根据imei 查询pin 码
     */
    @GetMapping("/pin")
    public Result<String> queryByImei(@RequestParam String imei) {
        AndroidDeviceVO androidDeviceVO = this.deviceFacade.getDeviceByImei(imei);
        return Result.success(androidDeviceVO.getPin());
    }

    /**
     * 根据imei查询旋转柜角度信息
     */
    @PostMapping("/queryAngleByImei")
    public List<AndroidDeviceAngleVO> queryAngleByImei(@RequestBody NoArgRequest req) {
        return this.deviceFacade.queryAngleByImei(req.getImei());
    }

}

